package com.example.supplychainbackend.entity.logistic;

import com.example.supplychainbackend.tool.DateTimeUtils;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicInteger;

@Entity
@Table(name = "domestic_logistic")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DomesticLogisticEntity {
    @Id
    String trackingNumber;

    String	worker1;
    String	worker2;
    String	address1;
    String	address2;
    String	phone1;
    String	phone2;
    Integer	status;

    String	userName;
    String	enterpriseName;
    Boolean	onChain;
    String	transactionId;
    String	commitTime;
    String	userId;
    String	enterpriseId;

    @Transient
    private static final AtomicInteger counter = new AtomicInteger(1);

    @PrePersist
    public void generateId() {
        if (trackingNumber == null|| trackingNumber.equals("")) {
            trackingNumber = String.format("%s%s%04d",
                    "SF", DateTimeUtils.getCurrentDateForID(), counter.getAndIncrement());
        }
    }
}

